import type { PageResult, PermissionApi } from '#/api/types';

import { Http as http } from '#/api/http';

/**
 * 更新权限
 * @param data 权限更新参数
 */
export async function updatePermissionApi(data: PermissionApi.UpdateParams) {
  return http.post<PermissionApi.PermissionVO>(
    '/system/permission/update',
    data,
  );
}

/**
 * 更新权限状态
 * @param data 状态更新参数
 */
export async function updatePermissionStatusApi(
  data: PermissionApi.StatusUpdateParams,
) {
  return http.post<string>('/system/permission/status/update', data);
}

/**
 * 获取权限列表
 * @param params 查询参数
 */
export async function getPermissionsApi(
  params: PermissionApi.PermissionListParams,
) {
  return http.get<PageResult<PermissionApi.PermissionVO>>(
    '/system/permission/list',
    params,
  );
}

/**
 * 获取权限树
 * @param params 查询参数
 */
export async function getPermissionTreeApi() {
  return http.get<PermissionApi.PermissionTree>('/system/permission/tree');
}

/**
 * 获取权限信息
 * @param permissionId 权限ID
 */
export async function getPermissionInfoApi(permissionId: string) {
  return http.get<PermissionApi.PermissionVO>('/system/permission/info', {
    permissionId,
  });
}

/**
 * 获取权限模块列表
 */
export async function getPermissionModuleApi() {
  return http.get<PermissionApi.PermissionModuleVO[]>(
    '/system/permission/module',
  );
}
